﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vds2465Telegrams;

namespace Vds2465Parser
{
	internal static class GenParse_AddressExtension
	{		
		#region private constants

		private const byte AddExt_1_InputByte = 0x01;
        private const byte AddExt_1_OutputByte = 0x02;
        private const byte AddExt_1_DisruptionByte = 0x10;

		private const byte AddExt_2_TimeToNextTestMessage = 0x50;
		private const byte AddExt_2_TestMessageInterval = 0x51;

		#endregion private constants

		#region internal methods

		internal static byte GenerateByte_AddExt_1(eAddressExtension_1 addressExtension)
		{
			byte addressExtensionByte = 0x0;

			switch(addressExtension)
			{
				case eAddressExtension_1.Input:
                    addressExtensionByte = AddExt_1_InputByte;
					break;
				case eAddressExtension_1.Output:
                    addressExtensionByte = AddExt_1_OutputByte;
					break;
				case eAddressExtension_1.Disruption:
                    addressExtensionByte = AddExt_1_DisruptionByte;
					break;
				default:
					// TODO handle error (unknown value for eAddressExtension)
					break;
			}

			return addressExtensionByte;
		}

        internal static bool ParseByte_AddExt_1(byte addressExtensionByte, out eAddressExtension_1 addressExtension)
		{
			// set default value
			bool bRetVal = true;
			addressExtension = eAddressExtension_1.Disruption;

			switch (addressExtensionByte)
			{
                case AddExt_1_InputByte:
					addressExtension = eAddressExtension_1.Input;
					break;
                case AddExt_1_OutputByte:
					addressExtension = eAddressExtension_1.Output;
					break;
                case AddExt_1_DisruptionByte:
					addressExtension = eAddressExtension_1.Disruption;
					break;
				default:
					// TODO handle error (unknown value for eAddressExtension)
					bRetVal = false;
					break;
			}

			return bRetVal;
		}

        internal static byte GenerateByte_AddExt_1_InputOutput(eAddressExtension_1_InputOutput addressExtension)
        {
            byte addressExtensionByte = 0x0;

            switch (addressExtension)
            {
                case eAddressExtension_1_InputOutput.Input:
                    addressExtensionByte = AddExt_1_InputByte;
                    break;
                case eAddressExtension_1_InputOutput.Output:
                    addressExtensionByte = AddExt_1_OutputByte;
                    break;
                default:
                    // TODO handle error (unknown value for eAddressExtension)
                    break;
            }

            return addressExtensionByte;
        }

        internal static bool ParseByte_AddExt_1_InputOutput(byte addressExtensionByte, out eAddressExtension_1_InputOutput addressExtension)
        {
            // set default value
            bool bRetVal = true;
            addressExtension = eAddressExtension_1_InputOutput.Input;

            switch (addressExtensionByte)
            {
                case AddExt_1_InputByte:
                    addressExtension = eAddressExtension_1_InputOutput.Input;
                    break;
                case AddExt_1_OutputByte:
                    addressExtension = eAddressExtension_1_InputOutput.Output;
                    break;
                default:
                    // TODO handle error (unknown value for eAddressExtension)
                    bRetVal = false;
                    break;
            }

            return bRetVal;
        }

		internal static byte GenerateByte_AddExt_2(eAddressExtension_2 addressExtension)
		{
			byte addressExtensionByte = 0x0;

			switch (addressExtension)
			{
				case eAddressExtension_2.TimeToNextTestMessage:
					addressExtensionByte = AddExt_2_TimeToNextTestMessage;
					break;
				case eAddressExtension_2.TestMessageInterval:
					addressExtensionByte = AddExt_2_TestMessageInterval;
					break;
				default:
					// TODO handle error (unknown value for eAddressExtension)
					break;
			}

			return addressExtensionByte;
		}

		internal static bool ParseByte_AddExt_2(byte addressExtensionByte, out eAddressExtension_2 addressExtension)
		{
			// set default value
			bool bRetVal = true;
			addressExtension = eAddressExtension_2.TestMessageInterval;

			switch (addressExtensionByte)
			{
				case AddExt_2_TimeToNextTestMessage:
					addressExtension = eAddressExtension_2.TimeToNextTestMessage;
					break;
				case AddExt_2_TestMessageInterval:
					addressExtension = eAddressExtension_2.TestMessageInterval;
					break;
				default:
					// TODO handle error (unknown value for eAddressExtension)
					bRetVal = false;
					break;
			}

			return bRetVal;
		}

		#endregion internal methods
	}
}
